package com.opencvjava.lessons.core;

import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.springframework.stereotype.Service;

import static com.opencvjava.support.util.CvUtils.imshow;
import static com.opencvjava.support.util.CvUtils.mat;
import static org.opencv.imgproc.Imgproc.*;
import static org.opencv.imgcodecs.Imgcodecs.*;

@Service
public class L1_IntroductionToOpenCV {

    public void test() {
//        Load and Display an Image
        Mat src = mat("lena.jpg");
        if (src.empty()) {
            throw new RuntimeException("读取失败");
        }
//        namedWindow("源图");
//        HighGui.imshow("源图", src);
        imshow("lena源图", src);
//        Load, Modify, and Save an Image
        Mat gray = new Mat();
        cvtColor(src, gray, COLOR_BGR2GRAY);
        imshow("lena灰度图", gray);
//        HighGui.imshow("lena灰度图", gray);
        imwrite("d:\\gray.jpg", gray);
    }
}
